﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using Com.CMS263.DAO;

namespace Com.CMS263.BLL
{
    public class GoodsBLL:BaseBLL<Good>
    {
        GoodsDAO dao = new GoodsDAO();
        public Good entity = new Good();
        public override Good GetModel()
        {
            return entity;
        }
        /// <summary>
        /// 查询全部
        /// </summary>
        /// <returns></returns>
        public IList<Good> FindAll()
        {
            return dao.FinlAll();
        }
      
        /// <summary>
        /// 模糊查询，分页
        /// </summary>
        /// <param name="key"></param>
        /// <param name="pagesize"></param>
        /// <param name="pageindex"></param>
        /// <returns></returns>

        public IList<Good> FindListByKey(int pagesize, int pageindex)
        {
            return dao.FindListByKey(pagesize,pageindex);
        }

        #region 根据品牌得到信息条数
        /// <summary>
        /// 根据品牌得到信息条数
        /// </summary>
        /// <param name="brandid"></param>
        /// <returns></returns>
        public int GetCountByBrandId(string brandid)
        {
            return dao.GetCountByBrandId(brandid);
        }
        #endregion

        ProdGoodsAttrBLL pbll = new ProdGoodsAttrBLL();
        public void AddGoods(Good good)
        {
            this.entity = good;
            this.Add();
            IList<ProdGoodsAttr> pglist = new List<ProdGoodsAttr>();
            pglist = good.ProdgoodAttrList;
            foreach (ProdGoodsAttr item in pglist)
            {
                item.GoodsId = entity.Id;
                pbll.entity = item;
                pbll.Add();
            }
           
        }

        public void UpDateModel(Good good)
        {
            IList<ProdGoodsAttr> pgaList = new List<ProdGoodsAttr>();
            pgaList = good.ProdgoodAttrList;
            this.entity = good;
            this.UpDate();
            int goodId = entity.Id;
            pbll.DelBygooId(goodId);
            
            foreach (ProdGoodsAttr item in pgaList)
            {
                item.GoodsId = entity.Id;
                pbll.entity = item;
                pbll.Add();
            }
        }

        public IList<Good> FindListByKey(string name, string isSale, string isDelete, string isBest, string isNew, int pageindex, int pagesize)
        {
            return dao.FindListByKey(name, isSale, isDelete, isBest, isNew, pageindex, pagesize);
        }

        public IList<Good> FindListByKey(string name, string isSale, string isDelete, string isBest, string isNew)
        {
            return dao.FindListByKey(name,isSale,isDelete,isBest,isNew);
        }
    }
}
